﻿Imports System.ComponentModel.DataAnnotations
Imports System.Globalization

Namespace Models.Validators

    ''' <summary>
    ''' Valida el campo si su valor insertado es una fecha o no
    ''' </summary>
    ''' <remarks></remarks>
    Public Class IsDateAttribute
        Inherits ValidationAttribute

        Public Overrides Function IsValid(value As Object) As Boolean
            If value Is Nothing Then Return True
            If Not Regex.IsMatch(value.ToString, "^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](201)\d$") Then Return True
            Return Date.TryParseExact(value.ToString, "dd/MM/yyyy", CultureInfo.GetCultureInfo("es-SV"), DateTimeStyles.None, New Date())
        End Function
    End Class
End Namespace
